#!/usr/bin/python3
# coding: utf-8
from common.read_ini import Dispose_ini
import os
class Command_Check():
    def __init__(self,file):
        self.ini = Dispose_ini(file)

    def check(self):
        ini_module_name='command_check'
        ini_list=self.ini.get_sections()
        fail_command_module_name=[]
        if ini_module_name in ini_list:
            ini_value=self.ini.get_items(ini_module_name)
            for i in ini_value:
                command_module_name=i[1].split('/')
                command_str=','.join(command_module_name)
                print(f'The detection command is as follows{command_str}')
                for j in command_module_name:
                    command_exist=os.popen(f'sudo which {j}')
                    if len(command_exist.read().strip()) != 0:
                        print('pass')

                    else:
                        print('fail')
                        fail_command_module_name.append(j)
        else:
            print('Skip command detection phase')
            return 0

        if len(fail_command_module_name) != 0 :
            print(f'Missing execute script command, missing command is as follows:{fail_command_module_name}')
            return 1
        else:
            return 0





if __name__ == '__main__':
    c=Command_Check('../config.ini')
    c.check()